package com.ruoyi.web.controller.script;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateTimeUtils;
import com.ruoyi.system.domain.WhCounter;
import com.ruoyi.system.domain.WhCounterGoods;
import com.ruoyi.system.mapper.WhCounterGoodsMapper;
import com.ruoyi.system.mapper.WhCounterMapper;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * @author: 陈平安
 * @date: 2023/3/7 22:04
 * @description: 脚本
 */
@RestController
@RequestMapping("/_back/script")
public class ScriptController {

    @Resource
    private WhCounterMapper counterMapper;
    @Resource
    private WhCounterGoodsMapper counterGoodsMapper;

    @GetMapping("/counter")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult counterData() {

        for (int i = 0; i < 50; i++) {
            WhCounter whCounter = new WhCounter();
            whCounter.setCode(((long) ((Math.random() * 9 + 1) * 100000000)) + "");
            whCounter.setLockCode(((long) ((Math.random() * 9 + 1) * 100000000)) + "");
            whCounter.setMaster("测试货柜主人" + (i + 1));
            whCounter.setMasterPhone(((long) ((Math.random() * 9 + 1) * 100000000)) + "");
            whCounter.setLoadingTime(DateTimeUtils.formatDate(new Date()));
            whCounter.setArrivalTime("2023-05-07");
            whCounter.setCompanyId(3);
            whCounter.setCreateBy("s_1");
            whCounter.setCreateTime(new Date());
            whCounter.setIsDelete(1);
            Integer[] ids = {1,8,9,14,26};
            counterMapper.insertWhCounter(whCounter);
            // 插入货物
            for (int j = 0; j < ids.length; j++) {
                WhCounterGoods counterGoods = new WhCounterGoods();
                counterGoods.setCounterId(whCounter.getId());
                counterGoods.setCustomerId(ids[j]);
                counterGoods.setCustomerGoods("测试货物" + ((int) ((Math.random() * 9 + 1) * 100000000)));
//                counterGoods.setGoodsNum((int) (Math.random() * 9 + 1));
//                counterGoods.setGoodsSquare(new BigDecimal((int) (Math.random() * 3 + 1)));
                counterGoods.setCreateBy("s_1");
                counterGoods.setCreateTime(new Date());
                counterGoods.setIsDelete(1);
                counterGoodsMapper.insertWhCounterGoods(counterGoods);
            }
        }
        return AjaxResult.success("操作成功");
    }

}
